package com.taomu.app.zongchouhuli.moudle.home.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;

import java.util.ArrayList;
import java.util.List;

public class HomeProductSpecialAdp extends RecyclerView.Adapter<HomeProductSpecialAdp.HomeProductSpecialHolder>{

    private Context mContext;

    private LayoutInflater inflater;

    private List<String> mData;

    public HomeProductSpecialAdp(Context mContext){
        this.mContext = mContext;
        this.mData = new ArrayList<>();
        this.inflater = LayoutInflater.from(mContext);
    }

    public void setData(List<String> mData){
        this.mData.clear();
        this.mData.addAll(mData);
        notifyDataSetChanged();
    }

    public void addData(List<String> mData){
        this.mData.addAll(mData);
        notifyDataSetChanged();
    }

    @Override
    public HomeProductSpecialHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_product_detail_special,parent,false);
        return new HomeProductSpecialHolder(view);
    }

    @Override
    public void onBindViewHolder(HomeProductSpecialHolder holder, int position) {
        final String entity = mData.get(position);
        holder.update(entity);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class HomeProductSpecialHolder extends RecyclerView.ViewHolder{

        private TextView mSpecialTv;

        public HomeProductSpecialHolder(View itemView) {
            super(itemView);
            mSpecialTv = itemView.findViewById(R.id.item_product_special_tv);
        }

        public void update(String entity){
            mSpecialTv.setText(entity);
        }
    }
}
